package com.bootdo.acitvity.listener.message.entity;

import com.bootdo.acitvity.listener.message.OrderAggregateRoot;
import com.bootdo.acitvity.listener.message.dto.PurchaseOrderDto;
import com.bootdo.acitvity.listener.message.dto.PurchaseOrderEventDto;
import com.bootdo.acitvity.listener.message.event.orderEvent.OrderEvent;
import com.bootdo.acitvity.listener.message.event.orderEvent.PurchaseOrderTransportEvent;
import lombok.Getter;
import lombok.Setter;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class PurchaseOrder extends Order {

    @Getter
    @Setter
    private PurchaseOrderDto purchaseOrderDto;

    public PurchaseOrder(String orderId) {
        super(orderId);
    }

    public void createTransportOrder(OrderAggregateRoot root) {
        List<OrderEvent> eventList = new LinkedList<>();

        PurchaseOrderTransportEvent purchaseOrderTransportEvent = new PurchaseOrderTransportEvent(orderId);

        Map<String, PurchaseOrder> purchaseOrders = root.getPurchaseOrders();
        PurchaseOrder purchaseOrder = purchaseOrders.get(orderId);
        /**
         * 采购订单头信息
         */
        PurchaseOrderDto purchaseOrderDto = purchaseOrder.getPurchaseOrderDto();
        PurchaseOrderEventDto purchaseEventDto = new PurchaseOrderEventDto();
        purchaseEventDto.setForderId(purchaseOrderDto.getFsupplierOrderId());

        purchaseOrderTransportEvent.setPurchaseOrderDto(purchaseEventDto);
        /**
         *  发布事件
         */
        eventList.add(purchaseOrderTransportEvent);
        publishEvent(eventList);
    }

}
